package job1.zkadmin;

import org.I0Itec.zkclient.ZkClient;

import java.nio.charset.StandardCharsets;

//用于修改存储在zookeeper上的mysql配置信息
public class ZkAdmin {
    public static void main(String[] args) {
//   储存在zookeeper上的mysql配置文件路径
        String mysqlConfZkPath = "/mysql_conf";
//  zk 客户端
        ZkClient zkClient;
//        创建zk客户端
        zkClient = new ZkClient("node1:2181,node2:2181");

//        如果配置文件不存在，则创建
        if (!zkClient.exists(mysqlConfZkPath)) {
//            创建持久化的配置文件
            zkClient.createPersistent(mysqlConfZkPath);
        }
        //第一份mysql 配置
        String mysqlConf = "driverClassName=com.mysql.jdbc.Driver\n" +
                "url=jdbc:mysql://node3:3306/mysql?characterEncoding=UTF-8\n" +
                "username=root\n" +
                "password=12345678\n" +
                "initialSize=5\n" +
                "maxActive=10\n" +
                "maxWait=3000";
//第二份mysql 配置
//        String mysqlConf = "driverClassName=com.mysql.jdbc.Driver\n" +
//                "url=jdbc:mysql://localhost:3306/mysql?characterEncoding=UTF-8\n" +
//                "username=root\n" +
//                "password=123456\n" +
//                "initialSize=5\n" +
//                "maxActive=10\n" +
//                "maxWait=3000";
//        向zk存储路径填写mysql配置信息
        zkClient.writeData(mysqlConfZkPath, mysqlConf.getBytes(StandardCharsets.UTF_8));
        System.out.println("成功修改zk上的mysql配置为\n" + mysqlConf);
    }
}
/*
/*
driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://node3:3306/db5?characterEncoding=UTF-8
username=root
password=123456
initialSize=5
maxActive=10
maxWait=3000
 */
